@extends('admin_system/public/layout')

<div class="main-container" data-ng-init="get_liveInfo()">
    {{--顶部导航--}}
    <div class="col-xs-12 top-nav nav">
        <p class="float-left nav-path"><strong>当前位置：</strong>直播管理>>添加、编辑直播</p>

        {{--返回按钮--}}
        <button type="button" class="btn btn-default float-right back" aria-label="Left Align">
            <span class="glyphicon glyphicon-arrow-left back" aria-hidden="true"></span>
            <span>返回</span>
        </button>
    </div>

    <div class="h10 col-xs-12"></div>

    <form action="/admin_system/live/add_live" id="form" method="post" enctype="multipart/form-data">
        {{csrf_field()}}
        <div class="content-box col-xs-12 mt20 pb20 pt20">
            <table class="table table-bordered">
                <tr>
                    <th>直播名称：</th>
                    <td><input class="form-control" name="live_title" value="{{old('live_title')}}" required="required">
                    </td>
                    <th>直播通知：</th>
                    <td><input class="form-control" name="notice" id="notice" value="{{old('notice')}}"
                               required="required"></td>
                </tr>
                <tr>
                    <th>封面图片：</th>
                    <td>
                        <input type=file class="form-control" id="face_img" name="face_img" required="required">
                    </td>
                    <th>是否显示直播</th>
                    <td>
                        <select class="form-control" name="is_show">
                            <option value="0">不显示</option>
                            <option value="1">显示</option>
                        </select>
                    </td>
                </tr>


                <tr>
                    <th>开始时间：</th>
                    <td>
                        <input type="datetime-local" class="form-control" name="begin_time" required="required">
                    </td>

                </tr>

                <tr>
                    <th>直播描述</th>
                    <td><input type="text" name="description" id="description" value="{{old('description')}}"
                               class="form-control"
                               required="required"></td>

                </tr>

                <tr>
                    <th>订阅头像:</th>
                    <td>
                        <input type="file" class="form-control" id="ad_img" name="ad_img"
                               style="display: block !important;" required="required">
                    </td>
                    <th>是否发布订阅:</th>
                    <td>
                        <select class="form-control" name="is_show_ad">
                            <option value="0">不发布</option>
                            <option value="1">发布</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <th>订阅文字:</th>
                    <td>
                        <input type="text" class="form-control" id="ad_red" value="{{old('ad_text')}}" name="ad_text"
                               required="required">

                    </td>
                    <th>直播类型</th>
                    <td>
                        <select name="live_type" id="inputID" class="form-control">
                            <option value="3"> -- 所有人 --</option>
                            {{--<option value="2"> -- 付费用户 --</option>--}}
                            <option value="1"> -- 学习官 --</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>直播推送消息</th>
                    <td>
                        <input type="text" class="form-control" id="push_msg" value="{{old('push_msg')}}"
                               name="push_msg"
                               required="required">
                    </td>
                </tr>
            </table>

            <div class="text-center">
                <button class="btn btn-danger" type="submit" id="tijiao">提&nbsp;&nbsp;交</button>
            </div>

        </div>
    </form>
    <script>
        @if(session('time_err'))
        alert('{{session('time_err')}}')
                @endif
        let notice = document.getElementById('notice');
        let push_msg = document.getElementById('push_msg');
        let ad_text = document.getElementById('ad_red');
        let description = document.getElementById('description');
        let link_url = document.getElementById('link_url');
        let tijiao = document.getElementById('form');

        //通知
        notice.addEventListener('blur', function () {
            let notice_val = notice.value;
            if (notice_val.length >= 15) {
                alert('输入文字过多');
            }
        });
        //激光推送
        push_msg.addEventListener('blur', function () {
            let push_msg_val = push_msg.value;
            if (push_msg_val.length >= 15) {
                alert('输入的文字过多');
            }
        })
        //订阅文字
        ad_text.addEventListener('blur', function () {
            let ad_text_val = ad_text.value;
            if (ad_text_val.length >= 15) {
                alert('输入的文字过多');
            }
        })
        //直播描述
        description.addEventListener('blur', function () {
            let description_val = description.value;
            if (description_val.length > 20) {
                alert('输入的文字过多20个以内');
            }
        })
        //直播链接
        link_url.addEventListener('blur', function () {
            let link_url_val = link_url.value;
            let reg = /(http|https)/;
            if (reg.test(link_url_val) === false) {
                alert('请输入带有http或者https协议的有效链接');
            }
        })
        tijiao.addEventListener('submit', function (e) {
            e.preventDefault();

            e.target.style.display = 'none';

            setTimeout(function () {
                let link_url_val = link_url.value;
                let reg = /(http|https)/;
                if (reg.test(link_url_val) === false) {
                    alert('请输入带有http或者https协议的有效链接');
                    return false;
                } else {
                    tijiao.submit();
                }
            },20000)
        });

    </script>
</div>